package com.wise.service.cms.content.product;

import com.alibaba.fastjson.JSON;
import com.wise.entities.content.Product;
import com.wise.framework.daomodel.DaoOne;
import com.wise.summer.v1.cms.content.product.GetProductById;
import org.springframework.stereotype.Service;
import org.summerframework.model.SummerService;
import org.summerframework.model.SummerServiceBean;

import static com.wise.model.content.ContentErrMsgs.Err_001000250009;

/**
 * @author shaoming
 * @date 2019-09-09
 */
@Service
@SummerService
public class GetProductByIdService implements SummerServiceBean<GetProductById> {

	@Override
	public void sum(GetProductById summer) {
		Product product = DaoOne.s(Product.class, summer.getId(), Err_001000250009);
		if (summer.getReset() != null) {
			if (!summer.getReset()) {
				// 草稿
				if (product.getDraft() != null) {
					Product pro = JSON.parseObject(product.getDraft(), Product.class);
					summer.setSummerResult(pro);
				} else {
					summer.setSummerResult(product);
				}
			} else {
				summer.setSummerResult(product);
			}
		}else {
			summer.setSummerResult(product);
		}
	}
}
